package controller;

import java.rmi.AlreadyBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

public class Server {

	/**
	 * @param args
	 * @throws RemoteException 
	 * @throws AlreadyBoundException 
	 */
	public static void main(String[] args) throws Exception {
		
		Registry registry;
		
		ServicePlayer stubPlayer;
		ServicePlayerImpl servicePlayer;
		
		ServiceGame stubGame;
		ServiceGameImpl serviceGame;
		
		System.setProperty("java.rmi.server.hostname","localhost");
		  
		servicePlayer = new ServicePlayerImpl();
		serviceGame = new ServiceGameImpl();
		
		stubPlayer = (ServicePlayer) UnicastRemoteObject.exportObject(servicePlayer,0);
		stubGame   = (ServiceGame) UnicastRemoteObject.exportObject(serviceGame,0);
		
		registry = LocateRegistry.createRegistry(3000);  
		
		registry.bind("ServicePlayer", stubPlayer);
		registry.bind("ServiceGame", stubGame);
		
		System.out.println("Services enregistrés");
		
		Thread tPlayer = new Thread(servicePlayer);
		Thread tGame = new Thread(serviceGame);
		
		tPlayer.start();
		tGame.start();
	}

}
